using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SubSonic;
using Gospel;

public partial class Admin_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lbError.Visible = false;
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        Query q = Gospel.DB.User.CreateQuery();
        q.WHERE(Gospel.DB.User.Columns.Active, true);
        q.WHERE(Gospel.DB.User.Columns.LoginName, this.txtLogin.Text);
        q.WHERE(Gospel.DB.User.Columns.Password, this.txtPassword.Text);
        Gospel.DB.UserCollection col = new Gospel.DB.UserController().FetchByQuery(q);
        if (col.Count == 0)
        {
            this.lbError.Text = "Fail the authentication!";
            this.lbError.Visible = true;
        }
        else
        {
            Session["loggedin"] = col[0].PersonId;
            Response.Redirect("~/admin/content.aspx");
        }
    }
}
